// JavaScript Document
jQuery.extend({
    handleError: function (s, xhr, status, e) {
        // If a local callback was specified, fire it
        if (s.error) {
            s.error.call(s.context || s, xhr, status, e);
        }
        // Fire the global callback
        if (s.global) {
            (s.context ? jQuery(s.context) : jQuery.event).trigger(
                "ajaxError", [xhr, s, e]);
        }
    },

    createUploadIframe: function (id, uri) {
        //create frame
        var frameId = 'jUploadFrame' + id;

        if (window.ActiveXObject) {
            var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
            if (typeof uri == 'boolean') {
                io.src = 'javascript:false';
            }
            else if (typeof uri == 'string') {
                io.src = uri;
            }
        }
        else {
            var io = document.createElement('iframe');
            io.id = frameId;
            io.name = frameId;
        }
        io.style.position = 'absolute';
        io.style.top = '-1000px';
        io.style.left = '-1000px';

        document.body.appendChild(io);

        return io;
    },
    createUploadForm: function (id, fileElementId) {
        //create form
        var formId = 'jUploadForm' + id;
        var fileId = 'jUploadFile' + id;
        var form = jQuery('<form  action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
        var oldElement = jQuery('#' + fileElementId);
        var newElement = jQuery(oldElement).clone();
        jQuery(oldElement).attr('id', fileId);
        jQuery(oldElement).before(newElement);
        jQuery(oldElement).appendTo(form);
        //set attributes
        jQuery(form).css('position', 'absolute');
        jQuery(form).css('top', '-1200px');
        jQuery(form).css('left', '-1200px');
        jQuery(form).appendTo('body');
        return form;
    },

    ajaxFileUpload: function (s) {
        // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout  
        s = jQuery.extend({}, jQuery.ajaxSettings, s);
        var id = s.fileElementId;
        var form = jQuery.createUploadForm(id, s.fileElementId);
        var io = jQuery.createUploadIframe(id, s.secureuri);
        var frameId = 'jUploadFrame' + id;
        var formId = 'jUploadForm' + id;

        if (s.global && !jQuery.active++) {
            // Watch for a new set of requests
            jQuery.event.trigger("ajaxStart");
        }
        var requestDone = false;
        // Create the request object
        var xml = {};
        if (s.global) {
            jQuery.event.trigger("ajaxSend", [xml, s]);
        }

        var uploadCallback = function (isTimeout) {
            // Wait for a response to come back
            var io = document.getElementById(frameId);
            try {
                if (io.contentWindow) {
                    xml.responseText = io.contentWindow.document.body ? io.contentWindow.document.body.innerHTML : null;
                    xml.responseXML = io.contentWindow.document.XMLDocument ? io.contentWindow.document.XMLDocument : io.contentWindow.document;

                } else if (io.contentDocument) {
                    xml.responseText = io.contentDocument.document.body ? io.contentDocument.document.body.innerHTML : null;
                    xml.responseXML = io.contentDocument.document.XMLDocument ? io.contentDocument.document.XMLDocument : io.contentDocument.document;
                }
            } catch (e) {
                jQuery.handleError(s, xml, null, e);
            }
            if (xml || isTimeout == "timeout") {
                requestDone = true;
                var status;
                try {
                    status = isTimeout != "timeout" ? "success" : "error";
                    // Make sure that the request was successful or notmodified
                    if (status != "error") {
                        // process the data (runs the xml through httpData regardless of callback)
                        var data = jQuery.uploadHttpData(xml, s.dataType);
                        if (s.success) {
                            // ifa local callback was specified, fire it and pass it the data
                            s.success(data, status);
                        }
                        ;
                        if (s.global) {
                            // Fire the global callback
                            jQuery.event.trigger("ajaxSuccess", [xml, s]);
                        }
                        ;
                    } else {
                        jQuery.handleError(s, xml, status);
                    }

                } catch (e) {
                    status = "error";
                    jQuery.handleError(s, xml, status, e);
                }
                ;
                if (s.global) {
                    // The request was completed
                    jQuery.event.trigger("ajaxComplete", [xml, s]);
                }
                ;


                // Handle the global AJAX counter
                if (s.global && !--jQuery.active) {
                    jQuery.event.trigger("ajaxStop");
                }
                ;
                if (s.complete) {
                    s.complete(xml, status);
                }
                ;

                jQuery(io).unbind();

                setTimeout(function () {
                    try {
                        jQuery(io).remove();
                        jQuery(form).remove();

                    } catch (e) {
                        jQuery.handleError(s, xml, null, e);
                    }

                }, 100);

                xml = null;

            }
            ;
        }
        // Timeout checker
        if (s.timeout > 0) {
            setTimeout(function () {

                if (!requestDone) {
                    // Check to see ifthe request is still happening
                    uploadCallback("timeout");
                }

            }, s.timeout);
        }
        try {
            var form = jQuery('#' + formId);
            jQuery(form).attr('action', s.url);
            jQuery(form).attr('method', 'POST');
            jQuery(form).attr('target', frameId);
            if (form.encoding) {
                form.encoding = 'multipart/form-data';
            }
            else {
                form.enctype = 'multipart/form-data';
            }
            jQuery(form).submit();

        } catch (e) {
            jQuery.handleError(s, xml, null, e);
        }
        if (window.attachEvent) {
            document.getElementById(frameId).attachEvent('onload', uploadCallback);
        }
        else {
            document.getElementById(frameId).addEventListener('load', uploadCallback, false);
        }
        return {
            abort: function () {
            }
        };

    },

    uploadHttpData: function (r, type) {
        var data = !type;
        data = type == "xml" || data ? r.responseXML : r.responseText;
        // ifthe type is "script", eval it in global context
        if (type == "script") {
            jQuery.globalEval(data);
        }

        // Get the JavaScript object, ifJSON is used.
        if (type == "json") {
            data = r.responseText;
            var start = data.indexOf(">");
            if (start != -1) {
                var end = data.indexOf("<", start + 1);
                if (end != -1) {
                    data = data.substring(start + 1, end);
                }
            }
            eval("data = " + data);
        }

        // evaluate scripts within html
        if (type == "html") {
            jQuery("<div>").html(data).evalScripts();
        }

        return data;
    }
});

/************ 初始化多图片数据开始 虞胜强 2018-7-25*****************/
function initCytImgMultUpload() {
    $(".cyt-img-mult-upload").each(function (index, obj) {
        var dataFileId = $(obj).attr("data-file-id");
        var dataInputId = $(obj).attr("data-input-id");
        var fileType = $(obj).attr("data-file-type");
        //初始化页面代码
        var s = '<ul class="cyt-img-list gallery">' +
            '<li class="cyt-img-list-add">' +
            '<input type="text" hidden id="' + dataInputId + '" name="' + dataInputId + '">' +
            '<input type="file" name="' + dataFileId + '" id="' + dataFileId + '" class="file" onchange="cytImgMultUpload(this,\'' + dataInputId + '\')" accept="' + fileType + '" multiple/>' +
            '<a onclick="cytImgMultClick(this,\'' + dataFileId + '\')" class="cy-add-o"></a>' +
            '</li>' +
            '</ul>';
        $(obj).html(s);
    })
}

/************ 初始化数据开始 虞胜强 2018-7-25*****************/
var baseMaxFont = 15;//最多展示字符数
/**********************************************/
/*
 **名称：通用组件多个图片上传封装js
 **描述：主要用于封装前端附件的组件。
 **开发人：虞胜强
 **创建时间：2018-7-25
 /**********************************************/

//点击事件
function cytImgMultClick(obj, id) {
    $(obj).parent().find("#" + id).click();
}

//批量上传
function cytImgMultUpload(obj, objectEntityId) {
    var files = obj.files;
    if (files.length > 10) {
        parent.alertBoxFalse("单次最多上传10张");
        return false;
    }
    for (var i = 0; i < files.length; i++) {
        var size = files[i].size;
        if (size > 20 * 1024 * 1024) {
            parent.alertBoxFalse("单张图片大小不能超过20M");
            return false;
        }
    }
    var objId = $(obj).attr("id");
    var objectId = $("#" + objectEntityId).val();
    $.ajaxFileUpload({
        //处理文件上传操作的服务器端地址(可以传参数,已亲测可用)
        url: '/platform/attachment/saveFilesToLocalByObjectId.do?objectId=' + objectId,
        secureuri: false,                   //是否启用安全提交,默认为false
        fileElementId: objId,               //文件选择框的id属性
        dataType: 'json',                   //服务器返回的格式,可以是json或xml等
        success: function (req) {          //服务器响应成功时的处理函数
            if (req.flag == "true") {
                var str = "";
                if (isBlank($("#" + objectEntityId).val())) {
                    $("#" + objectEntityId).val(req.data[0].objectId);
                }
                var num = $("#" + objectEntityId)[0].parentNode.parentNode.childNodes.length - 1;
                req.data.forEach(function (e) {
                    var iconPath = "";
                    if (e.path != null && e.path != "") {
                        var p = e.path.split(".");
                        iconPath = p[0] + "_icon." + p[1];
                    }
                    str += '<li onmouseover="cytImgMultMouseover(this,\'' + e.id + '\')" onmouseout="cytImgMultMouseout(this)">\
                                <input type="hidden" id=' + e.id + '>\
                                 <a href="javascript:void(0);" data-url="' + e.path + '" >\
                                   <img src="' + iconPath + '" data-src="' + e.path + '" onclick="showImage(' + num + ')" >\
                                </a>\
                            </li>';
                    num++;
                });
                $("#" + objectEntityId).parent().before(str);
            } else {
                parent.alertBoxFalse("上传失败");
            }
            $("#" + objId).attr("value", "");
            parent.setIframeHeight($(document).height()); //设置iframe的高度
        }
    });
}

var t = 1;
var price_tip_pop = null;

function cytImgMultMouseover(obj, objectId) {
    if (price_tip_pop != null) {
        clearTimeout(price_tip_pop);
        price_tip_pop = null;
    }
    clearTimeout(price_tip_pop);
    price_tip_pop = setTimeout(function () {
        if (t == 1) {
            $(obj).find('img').before("<span class='cy-cross' onmouseover='t2(this)' onmouseout='t1(this)' onclick='cytImgMultDelete(this,\"" + objectId + "\")'></span>");
        }
    }, 400);

}

function cytImgMultMouseout(obj) {
    if (price_tip_pop != null) {
        clearTimeout(price_tip_pop);
        price_tip_pop = null;
    }
    clearTimeout(price_tip_pop);
    price_tip_pop = setTimeout(function () {
        if (t == 1) {
            $(obj).find('span').remove();
        }
    }, 400);
}

function t1(obj) {
    t = 1;
}

function t2(obj) {
    t = 2;
}

/**
 * 图片删除
 * @param obj
 * @param objectId
 */
function cytImgMultDelete(obj, objectId) {
    var url = "/platform/attachment/deleteFile.do";
    var data = {"id": objectId};
    jQuery.AjaxGetMark(url, data, "json", function (req) {
        if (req.flag == "true") {
            $(obj).parent().parent().remove();
            t = 1;
            //通过回调函数设置值
            if (typeof cytCallBackImgMultDelete == 'function') {
                cytCallBackImgMultDelete(req);
            }
        } else {
            parent.alertBoxFalse("删除失败");
        }
    }, function () {
        parent.alertBoxFalse("删除失败");
    });
}

/**********************************************/

/*
 **名称：通用组件单个图片上传封装js
 **描述：主要用于封装前端附件的组件。
 **开发人：虞胜强
 **创建时间：2018-7-23
 /**********************************************/
function cytImgUpload(objId, catalog, showId,token,size) {
    debugger;
    if(size != null && size != "" && size != undefined && size != "undefined"){
        // 限制上传
        var length = $("#" + showId).children("li").length;
        console.log(length);
        if (length > (size-1)){
            $.toast("您发布的图片不能超过"+size+"张", "text");
            return false;
        }
    }else{
        size = 100;
    }
    var objectId = $("#" + showId).attr("data-objectId");
    $.showLoading("图片上传中");
    $.ajaxFileUpload({
        //处理文件上传操作的服务器端地址(可以传参数,已亲测可用)
        url: '/sysFile/singleImageNew?objectId=' + objectId + '&catalog='+catalog+'&token='+token,
        secureuri: false,                   //是否启用安全提交,默认为false
        fileElementId: objId,                //文件选择框的id属性
        dataType: 'json',                    //服务器返回的格式,可以是json或xml等
        success: function (rows) {
            $.hideLoading();
            //服务器响应成功时的处理函数
            if (rows.code == 0) {
                var str = '';
                str += '<li class="weui-uploader__file"><img onclick="showImg(\'' + rows.data.id + '\')" src="/sysFile/showFileByPath?path='+ rows.data.path +'" style="file"/>';
                str += '<div class="weui-gallery" onclick="hideImg()" id="img_' + rows.data.id + '" style="display: none"><div class="filepic"><img class="" src="/sysFile/showFileByPath?path=' + rows.data.path + '"/></div>';
                str += '<div class="weui-gallery__opr"><a href="javaScript:void(0)" class="weui-gallery__del"><i onclick="deleteImg(this,\'' + rows.data.id + '\')" class="weui-icon-delete weui-icon_gallery-delete"></i></a></div></div>';
                str += '</li>';
                $("#" + showId).append(str);
                $("#" + showId).attr("data-objectId", rows.data.objectId);
                var t='<input id="'+objId+'" name="file" class="weui-uploader__input" type="file" accept="image/*" multiple="" onchange="cytImgUpload(\''+objId+'\',\''+catalog+'\',\''+showId+'\',\''+token+'\',\''+size+'\')">';
                $("#" + objId).parent().html(t);
            } else {
                //parent.alertBoxFalse("上传失败");
                $.toast("上传失败", "text");
            }
        }
    });
}

/**********************************************/
/*
 **名称：微信端通用组件单个视频单个图片上传
 **描述：主要用于封装前端附件的组件。checkSize控制图片大小，length控制上传数量
 *      target是上传对象，一般是this
 *      catalog上传文件保存路径，一般是模块名称
 *      objId是sysfile系统文件，如果为空则自动添加默认
 *      userId是用户
 *      showId用于预览位置
 **开发人：陶聪聪
 **创建时间：2019-3-23
 /**********************************************/
function wxImgUpload(target,catalog, objId, userId, showId) {
    var check = checkSize(target,1024*200);
    if(!check){
        return false;
    }
    // 限制上传
    var length = $("#" + showId).children("li").length;
    if (length > 8){
        $.toast("您发布的班级圈图片不能超过九张", "text");
        return false;
    }
    var objectId = $("#" + showId).attr("data-objectId");

    var extend = target.value.substring(target.value.lastIndexOf(".")+1);
    if(extend == "gif" || extend == "jpg" || extend == "jpeg" || extend == "bmp" || extend == "png" || extend == "psd"){
        $.showLoading("正在上传中");
        if ($("#" + showId).find('video').length > 0) {
            objectId="";
        }
    }else {
        $.showLoading("正在转码中");
        if ($("#" + showId).find('img').length > 0) {
            objectId="";
        }
    }

    $.ajaxFileUpload({
        //处理文件上传操作的服务器端地址(可以传参数,已亲测可用)
        url: '/phone/sysFile/singleFileNoSave?objectId=' + objectId + '&userId=' + userId+'&catalog='+catalog+'&doType=1',
        secureuri: false,                   //是否启用安全提交,默认为false
        fileElementId: objId,                //文件选择框的id属性
        dataType: 'json',                    //服务器返回的格式,可以是json或xml等
        success: function (rows) {          //服务器响应成功时的处理函数
            if (rows.code == 0) {
                var str = '';
                $.hideLoading();
                if(rows.data.extendName == "gif" || rows.data.extendName == "jpg" || rows.data.extendName == "jpeg" || rows.data.extendName == "bmp" ||
                    rows.data.extendName == "png" || rows.data.extendName == "psd"){
                    str += '<li class="weui-uploader__file"><img onclick="showImg(\'' + rows.data.id + '\')" src="' + rows.data.path + '" style="width:100%; height:100%;"/>';
                    str += '<div class="weui-gallery" onclick="hideImg()" id="img_' + rows.data.id + '" style="display: none"><div class="filepic"><img class="" src="' + rows.data.path + '"/></div>';
                    str += '<div class="weui-gallery__opr"><a href="javaScript:void(0)" class="weui-gallery__del"><i onclick="deleteWxImg(this,\'' + rows.data.id + '\')" class="weui-icon-delete weui-icon_gallery-delete"></i></a></div></div>';
                    str += '</li>';
                    // 如果前面的有视频，就html替换，查询下面有video标签
                    if ($("#" + showId).find('video').length == 0) {
                        $("#" + showId).append(str);
                    } else {
                        $("#" + showId).html(str);
                    }
                    $("#" + showId).attr("data-objectId", rows.data.objectId);
                    var t='<input id="'+objId+'" name="file" class="weui-uploader__input" type="file" accept="image/*" multiple="" onchange="wxImgUpload(this,\''+catalog+'\',\''+objId+'\',\''+userId+'\',\''+showId+'\')">';
                    $("#" + objId).parent().html(t);
                    $("#type").val("1");
                } else if (rows.data.extendName == "mp4"){
                    str += '<li class="weui-uploader__file"><video style="width: 78px;height: 78px" src="'+rows.data.path+'" controls="controls">your browser does not support the video tag</video>';
                    str += '</li>';
                    $("#" + showId).html(str);
                    $("#" + showId).attr("data-objectId", rows.data.objectId);
                    //$(".showUpload").hide();
                    $("#type").val("2");
                    var t='<input id="'+objId+'" name="file" class="weui-uploader__input" type="file" accept="video/mp4" multiple="" onchange="wxImgUpload(this,\''+catalog+'\',\''+objId+'\',\''+userId+'\',\''+showId+'\')">';
                    $("#" + objId).parent().html(t);
                } else {
                    $.toast("格式错误，您上传的文件必须是照片、视频", "text");
                }

            } else {
                $.toast("上传失败", "text");
            }
        }
    });
}

/*
 **名称：通用组件多个图片上传封装js
 **描述：主要用于封装前端附件的组件。
 **开发人：虞胜强
 **创建时间：2018-7-23
 /**********************************************/
function cytMultiImgUpload(objId, userId, showId) {
    var objectId = $("#" + showId).attr("data-objectId");
    $("#" + objId).value = null;
    $.ajaxFileUpload({
        //处理文件上传操作的服务器端地址(可以传参数,已亲测可用)
        url: '/phone/sysFile/multiFileNoSave?objectId=' + objectId + '&userId=' + userId,
        secureuri: false,                   //是否启用安全提交,默认为false
        fileElementId: objId,                //文件选择框的id属性
        dataType: 'json',                    //服务器返回的格式,可以是json或xml等
        success: function (rows) {          //服务器响应成功时的处理函数
            if (rows.code === 0) {
                var str = '';
                for (var i = 0; i < rows.data.length; i++) {
                    str += '<li class="weui-uploader__file"><img onclick="showImg(\'' + rows.data[i].id + '\')" src="' + rows.data[i].path + '" style="width:100%; height:100%;"/>';
                    str += '<div class="weui-gallery" onclick="hideImg()" id="img_' + rows.data[i].id + '" style="display: none"><div class="filepic"><img class="" src="' + rows.data[i].path + '"/></div>';
                    str += '<div class="weui-gallery__opr"><a href="javaScript:void(0)" class="weui-gallery__del"><i onclick="deleteImg(this,\'' + rows.data[i].id + '\')" class="weui-icon-delete weui-icon_gallery-delete"></i></a></div></div>';
                    str += '</li>';
                }
                $("#" + showId).append(str);
                $("#" + showId).attr("data-objectId", rows.data[0].objectId);
            } else {
                $.toast("上传失败", "text");
            }
        }
    });
}

function hideImg() {
    $('.weui-gallery').hide();
}

function showImg(id) {
    $("#img_" + id).show();
}

function deleteImg(obj, id) {
    $.post("/sysFile/deleteById", {id: id}, function (result) {
        if (result.code === 0) {
            $("#img_" + id).hide();
            $(obj).parent().parent().parent().parent().remove();
        }
    });
}

function deleteWxImg(obj, id) {
    $.fn.doPost("/phone/sysFile/deleteFileById", {id: id}, function (result) {
        if (result.code === 0) {
            $("#img_" + id).hide();
            $(obj).parent().parent().parent().parent().remove();
        }
    });
}

//展示图片
function cytShowPic(objectId, showId) {
    $.post("/sysFile/list", {"objectId": objectId}, function (result) {
        if (result.code == 0) {
            if (result.data != null && result.data.length > 0) {
                for (var i = 0; i < result.data.length; i++) {
                    var obj = result.data[i];
                    if (obj.extendName == "png" || obj.extendName == "jpg" || obj.extendName == "jpeg" || obj.extendName == "gif") {
                        var str = '';
                        str += '<li class="weui-uploader__file"><img onclick="showImg(\'' + obj.id + '\')" src="/sysFile/showFileByPath?path='+ obj.path +'" style="width:100%; height:100%;"/>';
                        str += '<div class="weui-gallery" onclick="hideImg()" id="img_' + obj.id + '" style="display: none"><div class="filepic"><img class="" src="/sysFile/showFileByPath?path=' + obj.path + '"/></div>';
                        str += '</div>';
                        str += '</li>';
                        $("#" + showId).append(str);
                    }
                }
            }
        } else {
            $.toast(result.msg, "text");
        }
    }, "json");
}

//展示附件
function cytShowFile(objectId, showId) {
    $.post("/phone/sysFile/acceptFileByOpenId", {"objectId": objectId}, function (result) {
        if (result.code == 0) {
            if (result.data != null && result.data.length > 0) {
                for (var i = 0; i < result.data.length; i++) {
                    var obj = result.data[i];
                    var showContent = '<li>';
                    if (obj.extendName == "png" || obj.extendName == "jpg" || obj.extendName == "jpeg" || obj.extendName == "gif") {
                        showContent += '<img src="/mobile/img/Photo.png">';
                    } else if (obj.extendName == "pdf") {
                        showContent += '<img src="/mobile/img/Pdf.png">';
                    } else if (obj.extendName == "docx" || obj.extendName == "doc") {
                        showContent += '<img src="/mobile/img/Word.png">';
                    } else if (obj.extendName == "xls" || obj.extendName == "xlsx") {
                        showContent += '<img src="/mobile/img/Excel.png">';
                    } else if (obj.extendName == "txt") {
                        showContent += '<img src="/mobile/img/Txt.png">';
                    } else {
                        showContent += '<img src="/mobile/img/Atta.png">';
                    }
                    showContent += '<a href="' + obj.path + '"> ' + obj.fileName + '</a></li>';
                    $("#" + showId).append(showContent);
                }
            }
        } else {
            $.toast(result.msg, "text");
        }
    }, "json");
}

/**********************************************/

/*
 **名称：通用组件附件上传封装js
 **描述：主要用于封装前端附件的组件。
 **开发人：虞胜强
 **创建时间：2018-6-29
/**********************************************/
function cytFileUpload(objId, maxFont, objectType) {

    if (maxFont == null || maxFont == "" || maxFont <= 0) {
        maxFont = baseMaxFont;
    }
    var obj = $("#" + objId);
    var objectId = obj.parent().find(".cyt-file-ObjectId").val();
    if (isBlank(obj.attr("value"))) {
        return false;
    }
    var type = $("div[data-fileid='" + objId + "']").attr("data-file-type");
    if (objectId == null || objectId == "") {
        if (!(typeof(obj.parent().parent().attr("data-objectid")) == "undefined")) {
            objectId = obj.parent().parent().attr("data-objectid");
        }
    }
    $.ajaxFileUpload({
        //处理文件上传操作的服务器端地址(可以传参数,已亲测可用)
        url: '/platform/attachment/saveSigleFileToLocalByObjectId.do?objectId=' + objectId + '&objectType=' + objectType + '&width=600&height=600',
        secureuri: false,                   //是否启用安全提交,默认为false
        fileElementId: objId,                //文件选择框的id属性
        dataType: 'json',                    //服务器返回的格式,可以是json或xml等
        success: function (rows) {          //服务器响应成功时的处理函数
            debugger
            if (rows.flag) {
                if (rows.data != null) {
                    if (type != '1') {
                        parent.clearIframeHeight(); //清空iframe的高度
                    }
                    if (objectId == "" || objectId == null) {
                        $("#" + objId).parent().find(".cyt-file-ObjectId").val(rows.data.objectId);
                    }
                    var index = rows.data.fileName.lastIndexOf("\.");
                    var showName = rows.data.fileName;
                    var name = rows.data.fileName.substring(0, index);
                    var imageType = rows.data.fileName.substring(index + 1, rows.data.fileName.length);
                    var pdfUrl = rows.data.pdfUrl;
                    if (maxFont > 0) {
                        if (maxFont < name.length) {
                            showName = name.substring(0, maxFont * 1 - 1) + "..." + name.substring(name.length - 1) + "." + imageType;
                        }
                    }
                    var str = '';
                    if (pdfUrl == "" || pdfUrl == null) {
                        if (imageType == "jpg" || imageType == "png" || imageType == "gif" || imageType == "JPEG") {
                            str += '<li><span class="cy-attachment cyt-color-green"></span>\
                        <span title="' + rows.data.fileName + '">' + showName + '</span>\
                        <a  class="cyt-color-green" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + rows.data.id + '&fileName=' + rows.data.fileName + '">下载</a>\
                        <a target="view_window" class="cyt-color-green" href="javascript:parent.layUiShowImage(\'' + rows.data.path.replace(/\\/g, "/") + '\')">预览</a>\
                        <a class="cyt-color-red" href="javascript:void(0);" onclick="cytFileDelete(this,\'' + rows.data.id + '\')">删除</a></li>';
                        } else if (imageType == "pdf") {
                            var path = rows.data.path.replace(/\\/g, "/");
                            str += '<li><span class="cy cy-attachment td-operate-green"></span>\
                        <span title="' + rows.data.fileName + '">' + showName + '</span>\
                        <a  class="cyt-color-green" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + rows.data.id + '&fileName=' + rows.data.fileName + '">下载</a>\
                        <a target="view_window" class="cyt-color-green" href="' + path + '">预览</a>\
                        <a class="cyt-color-red" onclick="cytFileDelete(this,\'' + rows.data.id + '\')">删除</a></li>';
                        } else {
                            str += '<li><span class="cy-attachment cyt-color-green"></span>\
                        <span title="' + rows.data.fileName + '">' + showName + '</span>\
                        <a  class="cyt-color-green" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + rows.data.id + '&fileName=' + rows.data.fileName + '">下载</a>\
                        <a class="cyt-color-red" onclick="cytFileDelete(this,\'' + rows.data.id + '\')">删除</a></li>';
                        }
                    } else {
                        str += '<li><span class="cy cy-attachment td-operate-green"></span>\
                        <span title="' + rows.data.fileName + '">' + showName + '</span>\
                        <a  class="cyt-color-green" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + rows.data.id + '&fileName=' + rows.data.fileName + '">下载</a>\
                        <a target="view_window" class="cyt-color-green" href="javascript:;" onclick="gotoPdfPage(\'' + rows.data.id + '\')">预览</a>\
                        <a class="cyt-color-red" onclick="cytFileDelete(this,\'' + rows.data.id + '\')">删除</a></li>';
                    }
                    $("#" + objId).parent().parent().find(".cyt-file-list").append(str);
                    if (type != '1') {
                        parent.setIframeHeight($(document).height() + 60);
                    }
                }
            } else {
                parent.alertBoxFalse("添加附件失败");
            }
            $("#" + objId).attr("value", "");
        },
    });
}

/***
 * 初始化弹窗式带上传的附件
 * @param objId
 * @param objectId
 * @param title
 */
function cytWindowFileShow(objectId, fn, title) {
    if (title == null || title == "") {
        title = "附件上传";
    }
    parent.openLayerDel(title, CONTEXTPATH + "/system/uploadfile/cytUserUploadFile.do?objectId=" + objectId, 580, 500, function (layer, index) {
        var body = layer.getChildFrame('body', index);
    }, function (layer, index) {
        var body = layer.getChildFrame('body', index);
        var objectId = body.find(".cyt-file-ObjectId").val();
        // 判断是否有附件，没有就置空objectId
        var fileLength = body.find(".cyt-file-list li").length;
        if (fileLength == 0) {
            objectId = "";
        }
        fn(objectId);
    });
}

function cytPjIndexWindowFileShow(objectId, indexId, beEvaluatedId, latestDate, fn, title) {
    if (title == null || title == "") {
        title = "附件上传";
    }
    parent.openLayerDel(title, CONTEXTPATH + "/system/uploadfile/cytPjIndexUploadFile.do?objectId=" + objectId + "&indexId=" + indexId +
        "&beEvaluatedId=" + beEvaluatedId + "&latestDate=" + latestDate, 580, 500, function (layer, index) {
        var body = layer.getChildFrame('body', index);
    }, function (layer, index) {
        var body = layer.getChildFrame('body', index);
        var objectId = body.find(".cyt-file-ObjectId").val();
        // 判断是否有附件，没有就置空objectId
        var noauthLength = body.find(".noauth").length;
        var fileLength = body.find(".cyt-file-list li").length;
        if (fileLength <= noauthLength) {
            objectId = "";
        }
        fn(objectId);
    });
}

/***
 * 初始化弹窗式带上传的附件
 * @param objId
 * @param objectId
 * @param title
 */
function cytWindowFileShowNoUpload(objectId, title) {
    if (title == null || title == "") {
        title = "附件展示";
    }
    parent.openLayerOneNew(title, CONTEXTPATH + "/system/uploadfile/cytNoUploadShowFile.do?objectId=" + objectId, 580, 500, function (layer, index) {
        var body = layer.getChildFrame('body', index);
    });
}

/***
 * 初始化带上传的附件
 * @param objId
 * @param objectId
 * @param dataList
 * @param maxFont 最多展示字符数
 */
function cytFileShow(objId, objectId, dataList, maxFont) {
    if (maxFont == null || maxFont == "" || maxFont <= 0) {
        maxFont = baseMaxFont;
    }
    if (objectId != "" && objectId != null) {
        $("#" + objId).parent().find(".cyt-file-ObjectId").val(objectId);
    }
    debugger
    var type = $("div[data-fileid='" + objId + "']").attr("data-file-type");
    dataList.forEach(function (e) {
        var index = e.fileName.lastIndexOf("\.");
        var imageType = e.fileName.substring(index + 1, e.fileName.length);
        var showName = e.fileName;
        var name = e.fileName.substring(0, index);
        if (maxFont > 0) {
            if (maxFont < name.length) {
                showName = name.substring(0, maxFont * 1 - 1) + "..." + name.substring(name.length - 1) + "." + imageType;
            }
        }
        var pdfUrl = e.pdfUrl;
        var str = '';
        if (pdfUrl == "" || pdfUrl == null) {
            if (imageType == "jpg" || imageType == "png" || imageType == "gif" || imageType == "JPEG") {
                str += '<li><span class="cy-attachment cyt-color-green"></span>\
                        <span title="' + e.fileName + '">' + showName + '</span>\
                        <a  class="cyt-color-green" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + e.id + '&fileName=' + e.fileName + '">下载</a>\
                        <a target="view_window" class="td-operate-green" href="javascript:parent.layUiShowImage(\'' + e.path.replace(/\\/g, "/") + '\')">预览</a>\
                        <a class="cyt-color-red" href="javascript:void(0);" onclick="cytFileDelete(this,\'' + e.id + '\')">删除</a></li>';
            } else if (imageType == "pdf") {
                var path = e.path.replace(/\\/g, "/");
                str += '<li><span class="cy-attachment cyt-color-green"></span>\
                        <span title="' + e.fileName + '">' + showName + '</span>\
                        <a  class="cyt-color-green" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + e.id + '&fileName=' + e.fileName + '">下载</a>\
                        <a target="view_window" class="td-operate-green" href="' + path + '">预览</a>\
                        <a class="cyt-color-red" onclick="cytFileDelete(this,\'' + e.id + '\')">删除</a></li>';
            } else {
                str += '<li><span class="cy-attachment cyt-color-green"></span>\
                        <span title="' + e.fileName + '">' + showName + '</span>\
                        <a  class="cyt-color-green" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + e.id + '&fileName=' + e.fileName + '">下载</a>\
                        <a class="cyt-color-red" onclick="cytFileDelete(this,\'' + e.id + '\')">删除</a></li>';
            }
        } else {
            var path = e.path.replace(/\\/g, "/");
            str += '<li><span class="cy-attachment cyt-color-green"></span>\
                        <span title="' + e.fileName + '">' + showName + '</span>\
                        <a  class="cyt-color-green" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + e.id + '&fileName=' + e.fileName + '">下载</a>\
                        <a target="view_window" class="cyt-color-green" href="javascript:;" onclick="gotoPdfPage(\'' + e.id + '\')">预览</a>\
                        <a class="cyt-color-red" onclick="cytFileDelete(this,\'' + e.id + '\')">删除</a></li>';
        }
        $("#" + objId).parent().parent().find(".cyt-file-list").append(str);
        if (type != "1") {
            parent.setIframeHeight($(document).height() + 60);
        }
    });
}

/***
 * 初始化展示的附件
 * @param objId
 * @param dataList
 */
function cytFileShowNoUpload(objId, dataList, maxFont) {
    if (maxFont == null || maxFont == "" || maxFont <= 0) {
        maxFont = baseMaxFont;
    }
    var type = $("#" + objId).attr("data-file-type");
    dataList.forEach(function (e) {
        var index = e.fileName.lastIndexOf("\.");
        var imageType = e.fileName.substring(index + 1, e.fileName.length);
        var showName = e.fileName;
        var name = e.fileName.substring(0, index);
        if (maxFont > 0) {
            if (maxFont < name.length) {
                showName = name.substring(0, maxFont * 1 - 1) + "..." + name.substring(name.length - 1) + "." + imageType;
            }
        }
        var pdfUrl = e.pdfUrl;
        var str = '';
        if (pdfUrl == "" || pdfUrl == null) {
            if (imageType == "jpg" || imageType == "png" || imageType == "gif" || imageType == "JPEG") {
                str += '<li><span class="cy-attachment cyt-color-green no-print"></span>\
                        <span title="' + e.fileName + '">' + showName + '</span>\
                        <span class="no-print"><a class="cyt-color-green" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + e.id + '&fileName=' + e.fileName + '">下载</a></span>\
                        <span class="no-print"><a target="view_window" class="cyt-color-green" href="javascript:parent.layUiShowImage(\'' + e.path.replace(/\\/g, "/") + '\')">预览</a></span>\
                        </li>';
            } else if (imageType == "pdf") {
                var path = e.path.replace(/\\/g, "/");
                str += '<li><span class="cy-attachment cyt-color-green no-print"></span>\
                        <span title="' + e.fileName + '">' + showName + '</span>\
                        <span class="no-print"><a class="cyt-color-green no-print" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + e.id + '&fileName=' + e.fileName + '">下载</a></span>\
                        <span class="no-print"><a target="view_window" class="cyt-color-green no-print" href="' + path + '">预览</a></span>\
                        </li>';
            } else {
                str += '<li><span class="cy-attachment cyt-color-green no-print"></span>\
                        <span title="' + e.fileName + '">' + showName + '</span>\
                        <span class="no-print"><a class="cyt-color-green no-print" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + e.id + '&fileName=' + e.fileName + '">下载</a></span>\
                        </li>';
            }
        } else {
            str += '<li><span class="cy-attachment cyt-color-green no-print"></span>\
                        <span title="' + e.fileName + '">' + showName + '</span>\
                        <span class="no-print"><a class="cyt-color-green no-print" href="/platform/news/downloadContentLocalByAttaId.do?attaId=' + e.id + '&fileName=' + e.fileName + '">下载</a></span>\
                       <span class="no-print"><a target="view_window" class="cyt-color-green" href="javascript:;" onclick="gotoPdfPage(\'' + e.id + '\')">预览</a></span>\
                        </li>';
        }
        $("#" + objId).append(str);
        if (type != "1") {
            parent.setIframeHeight($(document).height() + 60);
        }
    });
}

/**********************************************/

/*
 **名称：通用组件附件删除封装js
 **描述：主要用于封装前端附件的组件。
 **开发人：虞胜强
 **创建时间：2018-6-29
 /**********************************************/
function cytFileDelete(obj, atatId) {
    parent.confirmLayerTwo1("确定删除该文件吗？", function (index) {
        //确定
        var url = "/platform/attachment/deleteFile.do";
        var data = {"id": atatId};
        jQuery.AjaxGetMark(url, data, "json", function (response) {
            if (response.flag) {
                $(obj).parent().remove();
            }
            parent.layer.close(index);
        }, function () {
            parent.alertBoxFalse("删除失败");
        });
    }, function () {
        //取消
    });

}

/**********************************************/

/*
 **名称：通用组件附件选择封装js
 **描述：主要用于封装前端附件的组件。
 **开发人：虞胜强
 **创建时间：2018-6-29
 /**********************************************/
function cytSelectFile(obj) {
    $(obj).parent().find("input[type='file']").click();
}

function gotoPdfPage(objectId) {
    var params = {attaObjectId: objectId};
    $.fn.ApiGoToPdfPage(params, function (res) {
        console.log(res.data.pdfUrl);
        window.open(res.data.pdfUrl);

    }, function () {
    });

}

/*
 **名称：通用组件附件选择封装js
 **描述：主要用于封装前端附件的组件。
 **开发人：虞胜强
 **创建时间：2018-6-29
 /**********************************************/
function gotoPdfPageNew(objectId) {
    var params = {attaObjectId: objectId};

    $.fn.ApiGoToPdfPage(params, function (res) {
        //var viewHet=window.screen.availHeight;
        // var viewWid=window.screen.availWidth;
        var pdfUrl = "";
        pdfUrl = res.data.pdfUrl;
        console.log(res.data.pdfUrl);
        //window.open(res.data.pdfUrl);
        top.openLayerOneNew("附件查看", CONTEXTPATH + "/platform/attachment/pdfView.do?pdfUrl=" + pdfUrl, 1000, 650, function (layer, index) {
            var body = layer.getChildFrame('body', index);
        });
    }, function () {
    });

}

function checkSize(target,filemaxsize) {
    var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
    var fileSize = 0;
    if (isIE && !target.files) {
        var filePath = target.value;
        var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
        if(!fileSystem.FileExists(filePath)){
            $.toast("附件不存在，请重新输入！", "text");
            return false;
        }
        var file = fileSystem.GetFile (filePath);
        fileSize = file.Size;
    } else {
        fileSize = target.files[0].size;
    }
    var size = fileSize / 1024;
    if(size>filemaxsize){
        $.toast("附件大小不能大于"+filemaxsize/1024+"M！", "text");
        target.value ="";
        return false;
    }
    return true;
}